package top.someapp.user;

import androidx.annotation.NonNull;
import top.someapp.entity.User;

/**
 * @author zwz
 * Created on 2021-07-22
 */
class LoginPresenter implements LoginContract.Presenter {

    private final LoginContract.View view;
    private User mockUser;

    LoginPresenter(@NonNull LoginContract.View view) {
        this.view = view;
        mockUser = new User();
        mockUser.setName("admin");
        mockUser.setPassword("123");
    }

    @Override public void doLogin() {
        String name = view.getName();
        String password = view.getPassword();
        if (mockUser.getName().equals(name) && mockUser.getPassword().equals(password)) {
            view.onLoginResult(true, "登录成功！");
        } else {
            view.onLoginResult(false, "用户名或密码错误！");
        }
    }

    @Override public void start() {
        view.setName(mockUser.getName());
    }

    @Override public void onDestroy() {

    }
}
